package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.StageInvestigate;
import com.ruoyi.teaching.service.IStageInvestigateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 阶段问卷Controller
 *
 * @author sunshine
 * @date 2024-02-15
 */
@RestController
@RequestMapping("/investigate")
public class StageInvestigateController extends BaseController
{
    @Autowired
    private IStageInvestigateService stageInvestigateService;

    /**
     * 查询阶段问卷列表
     */
    @RequiresPermissions("teaching:investigate:list")
    @GetMapping("/list")
    public TableDataInfo list(StageInvestigate stageInvestigate)
    {
        startPage();
        List<StageInvestigate> list = stageInvestigateService.selectStageInvestigateList(stageInvestigate);
        return getDataTable(list);
    }

    /**
     * 导出阶段问卷列表
     */
    @RequiresPermissions("teaching:investigate:export")
    @Log(title = "阶段问卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StageInvestigate stageInvestigate)
    {
        List<StageInvestigate> list = stageInvestigateService.selectStageInvestigateList(stageInvestigate);
        ExcelUtil<StageInvestigate> util = new ExcelUtil<StageInvestigate>(StageInvestigate.class);
        util.exportExcel(response, list, "阶段问卷数据");
    }

    /**
     * 获取阶段问卷详细信息
     */
    @RequiresPermissions("teaching:investigate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stageInvestigateService.selectStageInvestigateById(id));
    }

    /**
     * 新增阶段问卷
     */
    @RequiresPermissions("teaching:investigate:add")
    @Log(title = "阶段问卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StageInvestigate stageInvestigate)
    {stageInvestigateService.insertStageInvestigate(stageInvestigate);
        return AjaxResult.success("新增成功");
    }

    /**
     * 修改阶段问卷
     */
    @RequiresPermissions("teaching:investigate:edit")
    @Log(title = "阶段问卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StageInvestigate stageInvestigate)
    {
        return toAjax(stageInvestigateService.updateStageInvestigate(stageInvestigate));
    }

    /**
     * 删除阶段问卷
     */
    @RequiresPermissions("teaching:investigate:remove")
    @Log(title = "阶段问卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stageInvestigateService.deleteStageInvestigateByIds(ids));
    }
}
